package jiangyeheng;

public class Main {
    public static void main(String[] args) {
        Student[] students = new Student[5];

        // 三个本科生（至少一个优秀）
        students[0] = new StudentG("张三", "G2023001", true, 92.5);  // 优秀
        students[1] = new StudentG("李四", "G2023002", false, 88.0); // 不优秀
        students[2] = new StudentG("王五", "G2023003", true, 82.0);  // 不优秀

        // 两个硕士生（至少一个优秀）
        students[3] = new StudentM("赵六", "M2023001", true, 3);     // 优秀
        students[4] = new StudentM("孙七", "M2023002", true, 1);     // 不优秀

        // 使用多态判断优秀学生并输出信息
        System.out.println("优秀学生信息:");
        System.out.println("========================");

        for (Student student : students) {
            if (student.isExcellent()) {
                student.printlnfo();
            }
        }

        // 输出所有学生信息
        System.out.println("\n所有学生信息:");
        System.out.println("========================");
        for (Student student : students) {
            student.printlnfo();
        }

    }
}
interface Student{
    void setName(String name);
    void setId(String id);
    void printlnfo();
    boolean isExcellent();
}//定义接口

class StudentG implements Student{
    private String name;
    private String id;
    private boolean isCET4Passed;
    private double lastYearScore;

    public StudentG(){}

    public StudentG(String name,String id,boolean isCET4Passed,double lastYearScore){
        this.name=name;
        this.id=id;
        this.isCET4Passed=isCET4Passed;
        this.lastYearScore=lastYearScore;
    }

    public void setCET4Passed(boolean passed){
        this.isCET4Passed=passed;
    }

    @Override
    public void setName(String name){
        this.name=name;
    }

    @Override
    public void setId(String id){
        this.id=id;
    }

    @Override
    public void printlnfo(){
        System.out.println("本科生信息:");
        System.out.println("姓名: " + name);
        System.out.println("学号: " + id);
        System.out.println("CET4通过: " + (isCET4Passed ? "是" : "否"));
        System.out.println("去年成绩: " + lastYearScore);
        System.out.println("是否优秀: " + (isExcellent() ? "是" : "否"));
        System.out.println("------------------------");
    }

    @Override
    public boolean isExcellent(){
        if(isCET4Passed&&lastYearScore>=85.0)
            return true;
        return false;
    }
}
class StudentM implements Student{
    private String name;
    private String id;
    private boolean isCET6Passed;
    private int paperCount;
    public StudentM() {

    }

    public StudentM(String name, String id, boolean isCET6Passed, int paperCount) {
        this.name = name;
        this.id = id;
        this.isCET6Passed = isCET6Passed;
        this.paperCount = paperCount;
    }

    @Override
    public void setName(String name) {
        this.name=name;
    }

    @Override
    public void setId(String id) {
        this.id=id;
    }

    @Override
    public void printlnfo() {
        System.out.println("硕士生信息:");
        System.out.println("姓名: " + name);
        System.out.println("学号: " + id);
        System.out.println("CET6通过: " + (isCET6Passed ? "是" : "否"));
        System.out.println("论文数量: " + paperCount);
        System.out.println("是否优秀: " + (isExcellent() ? "是" : "否"));
        System.out.println("------------------------");
    }

    @Override
    public boolean isExcellent() {
        if(isCET6Passed&&paperCount>=2)
            return true;
        return false;
    }
}
